
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 11/26/2014 10:47:12
-- Generated from EDMX file: F:\PKSoftManagement\DataAccessLayer\DBSoftPK.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [QlPhongKham];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_bn_BenhBanDau_NoiDungDieuTri_bn_HoSoBenhNhan]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[bn_BenhBanDau_NoiDungDieuTri] DROP CONSTRAINT [FK_bn_BenhBanDau_NoiDungDieuTri_bn_HoSoBenhNhan];
GO
IF OBJECT_ID(N'[dbo].[FK_bn_BenhBanDau_NoiDungDieuTri_TB_Departments]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[bn_BenhBanDau_NoiDungDieuTri] DROP CONSTRAINT [FK_bn_BenhBanDau_NoiDungDieuTri_TB_Departments];
GO
IF OBJECT_ID(N'[dbo].[FK_bn_BenhBanDau_NoiDungDieuTri_TB_Users]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[bn_BenhBanDau_NoiDungDieuTri] DROP CONSTRAINT [FK_bn_BenhBanDau_NoiDungDieuTri_TB_Users];
GO
IF OBJECT_ID(N'[dbo].[FK_bn_bn_TrieuChungBanDau_bn_dm_TrieuChung]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[bn_bn_TrieuChungBanDau] DROP CONSTRAINT [FK_bn_bn_TrieuChungBanDau_bn_dm_TrieuChung];
GO
IF OBJECT_ID(N'[dbo].[FK_bn_bn_TrieuChungBanDau_bn_HoSoBenhNhan]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[bn_bn_TrieuChungBanDau] DROP CONSTRAINT [FK_bn_bn_TrieuChungBanDau_bn_HoSoBenhNhan];
GO
IF OBJECT_ID(N'[dbo].[FK_bn_dm_CongCuDieuTri_GiaTien_bn_dm_CongCuDieuTri]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[bn_dm_CongCuDieuTri_GiaTien] DROP CONSTRAINT [FK_bn_dm_CongCuDieuTri_GiaTien_bn_dm_CongCuDieuTri];
GO
IF OBJECT_ID(N'[dbo].[FK_bn_dm_Thuoc_bn_dm_LoaiThuoc]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[bn_dm_Thuoc] DROP CONSTRAINT [FK_bn_dm_Thuoc_bn_dm_LoaiThuoc];
GO
IF OBJECT_ID(N'[dbo].[FK_bn_dm_TrieuChung_bn_dm_LoaiTrieuChung]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[bn_dm_TrieuChung] DROP CONSTRAINT [FK_bn_dm_TrieuChung_bn_dm_LoaiTrieuChung];
GO
IF OBJECT_ID(N'[dbo].[FK_bn_ThongTinXacDinhBenhBanDau_bn_HoSoBenhNhan]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[bn_ThongTinXacDinhBenhBanDau] DROP CONSTRAINT [FK_bn_ThongTinXacDinhBenhBanDau_bn_HoSoBenhNhan];
GO
IF OBJECT_ID(N'[dbo].[FK_bn_Thuoc_GiaTien_bn_dm_Thuoc]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[bn_Thuoc_GiaTien] DROP CONSTRAINT [FK_bn_Thuoc_GiaTien_bn_dm_Thuoc];
GO
IF OBJECT_ID(N'[dbo].[FK_bn_ToaDieuTriCongCu_bn_dm_CongCuDieuTri]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[bn_ToaDieuTriCongCu] DROP CONSTRAINT [FK_bn_ToaDieuTriCongCu_bn_dm_CongCuDieuTri];
GO
IF OBJECT_ID(N'[dbo].[FK_bn_ToaDieuTriCongCu_bn_HoSoBenhNhan]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[bn_ToaDieuTriCongCu] DROP CONSTRAINT [FK_bn_ToaDieuTriCongCu_bn_HoSoBenhNhan];
GO
IF OBJECT_ID(N'[dbo].[FK_bn_ToaThuoc_bn_HoSoBenhNhan]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[bn_ToaThuoc] DROP CONSTRAINT [FK_bn_ToaThuoc_bn_HoSoBenhNhan];
GO
IF OBJECT_ID(N'[dbo].[FK_bn_ToaThuocChiTietBenhNhan_bn_dm_Thuoc]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[bn_ToaThuocChiTietBenhNhan] DROP CONSTRAINT [FK_bn_ToaThuocChiTietBenhNhan_bn_dm_Thuoc];
GO
IF OBJECT_ID(N'[dbo].[FK_bn_ToaThuocChiTietBenhNhan_bn_ToaThuoc]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[bn_ToaThuocChiTietBenhNhan] DROP CONSTRAINT [FK_bn_ToaThuocChiTietBenhNhan_bn_ToaThuoc];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[bn_BenhBanDau_NoiDungDieuTri]', 'U') IS NOT NULL
    DROP TABLE [dbo].[bn_BenhBanDau_NoiDungDieuTri];
GO
IF OBJECT_ID(N'[dbo].[bn_bn_TrieuChungBanDau]', 'U') IS NOT NULL
    DROP TABLE [dbo].[bn_bn_TrieuChungBanDau];
GO
IF OBJECT_ID(N'[dbo].[bn_dm_CongCuDieuTri]', 'U') IS NOT NULL
    DROP TABLE [dbo].[bn_dm_CongCuDieuTri];
GO
IF OBJECT_ID(N'[dbo].[bn_dm_CongCuDieuTri_GiaTien]', 'U') IS NOT NULL
    DROP TABLE [dbo].[bn_dm_CongCuDieuTri_GiaTien];
GO
IF OBJECT_ID(N'[dbo].[bn_dm_LoaiThuoc]', 'U') IS NOT NULL
    DROP TABLE [dbo].[bn_dm_LoaiThuoc];
GO
IF OBJECT_ID(N'[dbo].[bn_dm_LoaiTrieuChung]', 'U') IS NOT NULL
    DROP TABLE [dbo].[bn_dm_LoaiTrieuChung];
GO
IF OBJECT_ID(N'[dbo].[bn_dm_Thuoc]', 'U') IS NOT NULL
    DROP TABLE [dbo].[bn_dm_Thuoc];
GO
IF OBJECT_ID(N'[dbo].[bn_dm_TrieuChung]', 'U') IS NOT NULL
    DROP TABLE [dbo].[bn_dm_TrieuChung];
GO
IF OBJECT_ID(N'[dbo].[bn_dm_Type]', 'U') IS NOT NULL
    DROP TABLE [dbo].[bn_dm_Type];
GO
IF OBJECT_ID(N'[dbo].[bn_HoSoBenhNhan]', 'U') IS NOT NULL
    DROP TABLE [dbo].[bn_HoSoBenhNhan];
GO
IF OBJECT_ID(N'[dbo].[bn_ThongTinXacDinhBenhBanDau]', 'U') IS NOT NULL
    DROP TABLE [dbo].[bn_ThongTinXacDinhBenhBanDau];
GO
IF OBJECT_ID(N'[dbo].[bn_Thuoc_GiaTien]', 'U') IS NOT NULL
    DROP TABLE [dbo].[bn_Thuoc_GiaTien];
GO
IF OBJECT_ID(N'[dbo].[bn_ToaDieuTriCongCu]', 'U') IS NOT NULL
    DROP TABLE [dbo].[bn_ToaDieuTriCongCu];
GO
IF OBJECT_ID(N'[dbo].[bn_ToaThuoc]', 'U') IS NOT NULL
    DROP TABLE [dbo].[bn_ToaThuoc];
GO
IF OBJECT_ID(N'[dbo].[bn_ToaThuocChiTietBenhNhan]', 'U') IS NOT NULL
    DROP TABLE [dbo].[bn_ToaThuocChiTietBenhNhan];
GO
IF OBJECT_ID(N'[dbo].[dm_LoaiDVTinh]', 'U') IS NOT NULL
    DROP TABLE [dbo].[dm_LoaiDVTinh];
GO
IF OBJECT_ID(N'[dbo].[dm_NhaCC]', 'U') IS NOT NULL
    DROP TABLE [dbo].[dm_NhaCC];
GO
IF OBJECT_ID(N'[dbo].[TB_Departments]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TB_Departments];
GO
IF OBJECT_ID(N'[dbo].[TB_Users]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TB_Users];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'bn_BenhBanDau_NoiDungDieuTri'
CREATE TABLE [dbo].[bn_BenhBanDau_NoiDungDieuTri] (
    [Id] int  NOT NULL,
    [IdThongTinBenhBanDau] int  NULL,
    [IdPhongDieuTri] int  NULL,
    [Date] datetime  NULL,
    [ChuanDoanBenh] nvarchar(max)  NULL,
    [IdBacSi] int  NULL,
    [GhiChu] nvarchar(max)  NULL,
    [HuongDieuTri] nvarchar(max)  NULL,
    [IdBenhNhan] int  NULL,
    [FileHinhAnh] nvarchar(max)  NULL
);
GO

-- Creating table 'bn_bn_TrieuChungBanDau'
CREATE TABLE [dbo].[bn_bn_TrieuChungBanDau] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [IdBenhNhan] int  NULL,
    [IdTrieuChung] int  NULL,
    [Date] datetime  NULL
);
GO

-- Creating table 'bn_dm_CongCuDieuTri'
CREATE TABLE [dbo].[bn_dm_CongCuDieuTri] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Ten] nvarchar(50)  NULL,
    [GiaTien] nvarchar(50)  NULL
);
GO

-- Creating table 'bn_dm_CongCuDieuTri_GiaTien'
CREATE TABLE [dbo].[bn_dm_CongCuDieuTri_GiaTien] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [IdCongCuDieuTri] int  NULL,
    [GiaTien] nvarchar(50)  NULL,
    [Active] bit  NULL
);
GO

-- Creating table 'bn_dm_LoaiThuoc'
CREATE TABLE [dbo].[bn_dm_LoaiThuoc] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Ten] int  NULL
);
GO

-- Creating table 'bn_dm_LoaiTrieuChung'
CREATE TABLE [dbo].[bn_dm_LoaiTrieuChung] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Ten] nvarchar(max)  NULL
);
GO

-- Creating table 'bn_dm_Thuoc'
CREATE TABLE [dbo].[bn_dm_Thuoc] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [IdLoaiThuoc] int  NULL,
    [MaThuoc] nvarchar(50)  NULL,
    [TenThuoc] nvarchar(max)  NULL,
    [TenVietTac] nvarchar(50)  NULL,
    [SLThuoc] nvarchar(50)  NULL,
    [DonGia] nvarchar(50)  NULL,
    [IsDelete] bit  NULL
);
GO

-- Creating table 'bn_dm_TrieuChung'
CREATE TABLE [dbo].[bn_dm_TrieuChung] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [IdLoaiTrieuChung] int  NULL,
    [Ten] nvarchar(max)  NULL,
    [IdType] int  NULL
);
GO

-- Creating table 'bn_HoSoBenhNhan'
CREATE TABLE [dbo].[bn_HoSoBenhNhan] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [MaThe] nvarchar(50)  NULL,
    [Ho] nvarchar(50)  NULL,
    [Ten] nvarchar(50)  NULL,
    [DiaChi] nvarchar(max)  NULL,
    [DienThoai] nvarchar(50)  NULL,
    [GioiTinh] bit  NULL,
    [Email] nvarchar(50)  NULL,
    [NamSinh] datetime  NULL,
    [IsDelete] bit  NULL,
    [IsFinish] bit  NULL
);
GO

-- Creating table 'bn_ThongTinXacDinhBenhBanDau'
CREATE TABLE [dbo].[bn_ThongTinXacDinhBenhBanDau] (
    [Id] int  NOT NULL,
    [GhiChuXacDinhBenhQuaTrieuChung] nvarchar(max)  NULL,
    [IdBenhNhan] int  NULL
);
GO

-- Creating table 'bn_Thuoc_GiaTien'
CREATE TABLE [dbo].[bn_Thuoc_GiaTien] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [IdThuoc] int  NULL,
    [GiaTien] nvarchar(50)  NULL,
    [IsActive] bit  NULL,
    [IsDelete] bit  NULL
);
GO

-- Creating table 'bn_ToaDieuTriCongCu'
CREATE TABLE [dbo].[bn_ToaDieuTriCongCu] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [IdBenhNhan] int  NULL,
    [IdCongCuDieuTri] int  NULL,
    [date] datetime  NULL,
    [Amount] nvarchar(50)  NULL
);
GO

-- Creating table 'bn_ToaThuoc'
CREATE TABLE [dbo].[bn_ToaThuoc] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [ThongTinLenToaThuoc] nvarchar(max)  NULL,
    [IdBenhNhan] int  NULL,
    [Date] datetime  NULL
);
GO

-- Creating table 'bn_ToaThuocChiTietBenhNhan'
CREATE TABLE [dbo].[bn_ToaThuocChiTietBenhNhan] (
    [Id] int  NOT NULL,
    [IdToaThuoc] int  NULL,
    [IdThuoc] int  NULL,
    [SL] nvarchar(50)  NULL,
    [DonGia] nvarchar(50)  NULL,
    [Amount] nvarchar(50)  NULL,
    [GhiChu] nvarchar(max)  NULL,
    [Date] datetime  NULL
);
GO

-- Creating table 'dm_LoaiDVTinh'
CREATE TABLE [dbo].[dm_LoaiDVTinh] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Ten] nvarchar(100)  NULL
);
GO

-- Creating table 'dm_NhaCC'
CREATE TABLE [dbo].[dm_NhaCC] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [TenNCC] nvarchar(100)  NULL,
    [DiaChi] nvarchar(500)  NULL,
    [SoDT] nvarchar(100)  NULL,
    [Fax] nvarchar(50)  NULL,
    [Mail] nvarchar(200)  NULL,
    [Website] nvarchar(200)  NULL,
    [IsNVL] bit  NULL,
    [IsKhongChon] bit  NULL,
    [MaST] nvarchar(50)  NULL,
    [NganHang] nvarchar(500)  NULL,
    [TaiKhoan] nvarchar(100)  NULL,
    [IsKhuVuc] int  NULL,
    [IdMaNCC] nvarchar(50)  NULL,
    [LocalName] nvarchar(500)  NULL,
    [ForeignName] nvarchar(max)  NULL
);
GO

-- Creating table 'TB_Departments'
CREATE TABLE [dbo].[TB_Departments] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [DepartmentName] nvarchar(255)  NULL,
    [DepartmentDesc] nvarchar(300)  NULL,
    [IdChief] int  NULL,
    [CreateBy] int  NULL,
    [UpdateBy] int  NULL,
    [CreateDate] datetime  NULL,
    [UpdateDate] datetime  NULL,
    [IsDelete] bit  NULL
);
GO

-- Creating table 'TB_Users'
CREATE TABLE [dbo].[TB_Users] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [UserName] varchar(256)  NOT NULL,
    [FirstName] nvarchar(200)  NULL,
    [LastName] nvarchar(200)  NULL,
    [Password] varchar(32)  NULL,
    [Department] int  NULL,
    [JobTitle] int  NULL,
    [BirthDay] datetime  NULL,
    [Email] varchar(256)  NULL,
    [Mobile] nvarchar(16)  NULL,
    [Sex] bit  NULL,
    [LastLoginDate] datetime  NULL,
    [LastPasswordChangedDate] datetime  NULL,
    [CreateDate] datetime  NULL,
    [UpdateDate] datetime  NULL,
    [CreateBy] int  NULL,
    [UpdateBy] int  NULL,
    [IsAdministrator] bit  NULL,
    [IsActive] bit  NULL,
    [IsDelete] bit  NULL,
    [SerialNumber] nvarchar(100)  NULL,
    [PassWordOld] nvarchar(500)  NULL,
    [HasChangePass] bit  NULL
);
GO

-- Creating table 'bn_dm_Type'
CREATE TABLE [dbo].[bn_dm_Type] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Ten] nvarchar(50)  NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'bn_BenhBanDau_NoiDungDieuTri'
ALTER TABLE [dbo].[bn_BenhBanDau_NoiDungDieuTri]
ADD CONSTRAINT [PK_bn_BenhBanDau_NoiDungDieuTri]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'bn_bn_TrieuChungBanDau'
ALTER TABLE [dbo].[bn_bn_TrieuChungBanDau]
ADD CONSTRAINT [PK_bn_bn_TrieuChungBanDau]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'bn_dm_CongCuDieuTri'
ALTER TABLE [dbo].[bn_dm_CongCuDieuTri]
ADD CONSTRAINT [PK_bn_dm_CongCuDieuTri]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'bn_dm_CongCuDieuTri_GiaTien'
ALTER TABLE [dbo].[bn_dm_CongCuDieuTri_GiaTien]
ADD CONSTRAINT [PK_bn_dm_CongCuDieuTri_GiaTien]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'bn_dm_LoaiThuoc'
ALTER TABLE [dbo].[bn_dm_LoaiThuoc]
ADD CONSTRAINT [PK_bn_dm_LoaiThuoc]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'bn_dm_LoaiTrieuChung'
ALTER TABLE [dbo].[bn_dm_LoaiTrieuChung]
ADD CONSTRAINT [PK_bn_dm_LoaiTrieuChung]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'bn_dm_Thuoc'
ALTER TABLE [dbo].[bn_dm_Thuoc]
ADD CONSTRAINT [PK_bn_dm_Thuoc]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'bn_dm_TrieuChung'
ALTER TABLE [dbo].[bn_dm_TrieuChung]
ADD CONSTRAINT [PK_bn_dm_TrieuChung]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'bn_HoSoBenhNhan'
ALTER TABLE [dbo].[bn_HoSoBenhNhan]
ADD CONSTRAINT [PK_bn_HoSoBenhNhan]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'bn_ThongTinXacDinhBenhBanDau'
ALTER TABLE [dbo].[bn_ThongTinXacDinhBenhBanDau]
ADD CONSTRAINT [PK_bn_ThongTinXacDinhBenhBanDau]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'bn_Thuoc_GiaTien'
ALTER TABLE [dbo].[bn_Thuoc_GiaTien]
ADD CONSTRAINT [PK_bn_Thuoc_GiaTien]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'bn_ToaDieuTriCongCu'
ALTER TABLE [dbo].[bn_ToaDieuTriCongCu]
ADD CONSTRAINT [PK_bn_ToaDieuTriCongCu]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'bn_ToaThuoc'
ALTER TABLE [dbo].[bn_ToaThuoc]
ADD CONSTRAINT [PK_bn_ToaThuoc]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'bn_ToaThuocChiTietBenhNhan'
ALTER TABLE [dbo].[bn_ToaThuocChiTietBenhNhan]
ADD CONSTRAINT [PK_bn_ToaThuocChiTietBenhNhan]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'dm_LoaiDVTinh'
ALTER TABLE [dbo].[dm_LoaiDVTinh]
ADD CONSTRAINT [PK_dm_LoaiDVTinh]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'dm_NhaCC'
ALTER TABLE [dbo].[dm_NhaCC]
ADD CONSTRAINT [PK_dm_NhaCC]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [ID] in table 'TB_Departments'
ALTER TABLE [dbo].[TB_Departments]
ADD CONSTRAINT [PK_TB_Departments]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'TB_Users'
ALTER TABLE [dbo].[TB_Users]
ADD CONSTRAINT [PK_TB_Users]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [Id] in table 'bn_dm_Type'
ALTER TABLE [dbo].[bn_dm_Type]
ADD CONSTRAINT [PK_bn_dm_Type]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [IdBenhNhan] in table 'bn_BenhBanDau_NoiDungDieuTri'
ALTER TABLE [dbo].[bn_BenhBanDau_NoiDungDieuTri]
ADD CONSTRAINT [FK_bn_BenhBanDau_NoiDungDieuTri_bn_HoSoBenhNhan]
    FOREIGN KEY ([IdBenhNhan])
    REFERENCES [dbo].[bn_HoSoBenhNhan]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_bn_BenhBanDau_NoiDungDieuTri_bn_HoSoBenhNhan'
CREATE INDEX [IX_FK_bn_BenhBanDau_NoiDungDieuTri_bn_HoSoBenhNhan]
ON [dbo].[bn_BenhBanDau_NoiDungDieuTri]
    ([IdBenhNhan]);
GO

-- Creating foreign key on [IdPhongDieuTri] in table 'bn_BenhBanDau_NoiDungDieuTri'
ALTER TABLE [dbo].[bn_BenhBanDau_NoiDungDieuTri]
ADD CONSTRAINT [FK_bn_BenhBanDau_NoiDungDieuTri_TB_Departments]
    FOREIGN KEY ([IdPhongDieuTri])
    REFERENCES [dbo].[TB_Departments]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_bn_BenhBanDau_NoiDungDieuTri_TB_Departments'
CREATE INDEX [IX_FK_bn_BenhBanDau_NoiDungDieuTri_TB_Departments]
ON [dbo].[bn_BenhBanDau_NoiDungDieuTri]
    ([IdPhongDieuTri]);
GO

-- Creating foreign key on [IdBacSi] in table 'bn_BenhBanDau_NoiDungDieuTri'
ALTER TABLE [dbo].[bn_BenhBanDau_NoiDungDieuTri]
ADD CONSTRAINT [FK_bn_BenhBanDau_NoiDungDieuTri_TB_Users]
    FOREIGN KEY ([IdBacSi])
    REFERENCES [dbo].[TB_Users]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_bn_BenhBanDau_NoiDungDieuTri_TB_Users'
CREATE INDEX [IX_FK_bn_BenhBanDau_NoiDungDieuTri_TB_Users]
ON [dbo].[bn_BenhBanDau_NoiDungDieuTri]
    ([IdBacSi]);
GO

-- Creating foreign key on [IdTrieuChung] in table 'bn_bn_TrieuChungBanDau'
ALTER TABLE [dbo].[bn_bn_TrieuChungBanDau]
ADD CONSTRAINT [FK_bn_bn_TrieuChungBanDau_bn_dm_TrieuChung]
    FOREIGN KEY ([IdTrieuChung])
    REFERENCES [dbo].[bn_dm_TrieuChung]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_bn_bn_TrieuChungBanDau_bn_dm_TrieuChung'
CREATE INDEX [IX_FK_bn_bn_TrieuChungBanDau_bn_dm_TrieuChung]
ON [dbo].[bn_bn_TrieuChungBanDau]
    ([IdTrieuChung]);
GO

-- Creating foreign key on [IdBenhNhan] in table 'bn_bn_TrieuChungBanDau'
ALTER TABLE [dbo].[bn_bn_TrieuChungBanDau]
ADD CONSTRAINT [FK_bn_bn_TrieuChungBanDau_bn_HoSoBenhNhan]
    FOREIGN KEY ([IdBenhNhan])
    REFERENCES [dbo].[bn_HoSoBenhNhan]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_bn_bn_TrieuChungBanDau_bn_HoSoBenhNhan'
CREATE INDEX [IX_FK_bn_bn_TrieuChungBanDau_bn_HoSoBenhNhan]
ON [dbo].[bn_bn_TrieuChungBanDau]
    ([IdBenhNhan]);
GO

-- Creating foreign key on [IdCongCuDieuTri] in table 'bn_dm_CongCuDieuTri_GiaTien'
ALTER TABLE [dbo].[bn_dm_CongCuDieuTri_GiaTien]
ADD CONSTRAINT [FK_bn_dm_CongCuDieuTri_GiaTien_bn_dm_CongCuDieuTri]
    FOREIGN KEY ([IdCongCuDieuTri])
    REFERENCES [dbo].[bn_dm_CongCuDieuTri]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_bn_dm_CongCuDieuTri_GiaTien_bn_dm_CongCuDieuTri'
CREATE INDEX [IX_FK_bn_dm_CongCuDieuTri_GiaTien_bn_dm_CongCuDieuTri]
ON [dbo].[bn_dm_CongCuDieuTri_GiaTien]
    ([IdCongCuDieuTri]);
GO

-- Creating foreign key on [IdCongCuDieuTri] in table 'bn_ToaDieuTriCongCu'
ALTER TABLE [dbo].[bn_ToaDieuTriCongCu]
ADD CONSTRAINT [FK_bn_ToaDieuTriCongCu_bn_dm_CongCuDieuTri]
    FOREIGN KEY ([IdCongCuDieuTri])
    REFERENCES [dbo].[bn_dm_CongCuDieuTri]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_bn_ToaDieuTriCongCu_bn_dm_CongCuDieuTri'
CREATE INDEX [IX_FK_bn_ToaDieuTriCongCu_bn_dm_CongCuDieuTri]
ON [dbo].[bn_ToaDieuTriCongCu]
    ([IdCongCuDieuTri]);
GO

-- Creating foreign key on [IdLoaiThuoc] in table 'bn_dm_Thuoc'
ALTER TABLE [dbo].[bn_dm_Thuoc]
ADD CONSTRAINT [FK_bn_dm_Thuoc_bn_dm_LoaiThuoc]
    FOREIGN KEY ([IdLoaiThuoc])
    REFERENCES [dbo].[bn_dm_LoaiThuoc]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_bn_dm_Thuoc_bn_dm_LoaiThuoc'
CREATE INDEX [IX_FK_bn_dm_Thuoc_bn_dm_LoaiThuoc]
ON [dbo].[bn_dm_Thuoc]
    ([IdLoaiThuoc]);
GO

-- Creating foreign key on [IdLoaiTrieuChung] in table 'bn_dm_TrieuChung'
ALTER TABLE [dbo].[bn_dm_TrieuChung]
ADD CONSTRAINT [FK_bn_dm_TrieuChung_bn_dm_LoaiTrieuChung]
    FOREIGN KEY ([IdLoaiTrieuChung])
    REFERENCES [dbo].[bn_dm_LoaiTrieuChung]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_bn_dm_TrieuChung_bn_dm_LoaiTrieuChung'
CREATE INDEX [IX_FK_bn_dm_TrieuChung_bn_dm_LoaiTrieuChung]
ON [dbo].[bn_dm_TrieuChung]
    ([IdLoaiTrieuChung]);
GO

-- Creating foreign key on [IdThuoc] in table 'bn_Thuoc_GiaTien'
ALTER TABLE [dbo].[bn_Thuoc_GiaTien]
ADD CONSTRAINT [FK_bn_Thuoc_GiaTien_bn_dm_Thuoc]
    FOREIGN KEY ([IdThuoc])
    REFERENCES [dbo].[bn_dm_Thuoc]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_bn_Thuoc_GiaTien_bn_dm_Thuoc'
CREATE INDEX [IX_FK_bn_Thuoc_GiaTien_bn_dm_Thuoc]
ON [dbo].[bn_Thuoc_GiaTien]
    ([IdThuoc]);
GO

-- Creating foreign key on [IdThuoc] in table 'bn_ToaThuocChiTietBenhNhan'
ALTER TABLE [dbo].[bn_ToaThuocChiTietBenhNhan]
ADD CONSTRAINT [FK_bn_ToaThuocChiTietBenhNhan_bn_dm_Thuoc]
    FOREIGN KEY ([IdThuoc])
    REFERENCES [dbo].[bn_dm_Thuoc]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_bn_ToaThuocChiTietBenhNhan_bn_dm_Thuoc'
CREATE INDEX [IX_FK_bn_ToaThuocChiTietBenhNhan_bn_dm_Thuoc]
ON [dbo].[bn_ToaThuocChiTietBenhNhan]
    ([IdThuoc]);
GO

-- Creating foreign key on [IdBenhNhan] in table 'bn_ThongTinXacDinhBenhBanDau'
ALTER TABLE [dbo].[bn_ThongTinXacDinhBenhBanDau]
ADD CONSTRAINT [FK_bn_ThongTinXacDinhBenhBanDau_bn_HoSoBenhNhan]
    FOREIGN KEY ([IdBenhNhan])
    REFERENCES [dbo].[bn_HoSoBenhNhan]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_bn_ThongTinXacDinhBenhBanDau_bn_HoSoBenhNhan'
CREATE INDEX [IX_FK_bn_ThongTinXacDinhBenhBanDau_bn_HoSoBenhNhan]
ON [dbo].[bn_ThongTinXacDinhBenhBanDau]
    ([IdBenhNhan]);
GO

-- Creating foreign key on [IdBenhNhan] in table 'bn_ToaDieuTriCongCu'
ALTER TABLE [dbo].[bn_ToaDieuTriCongCu]
ADD CONSTRAINT [FK_bn_ToaDieuTriCongCu_bn_HoSoBenhNhan]
    FOREIGN KEY ([IdBenhNhan])
    REFERENCES [dbo].[bn_HoSoBenhNhan]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_bn_ToaDieuTriCongCu_bn_HoSoBenhNhan'
CREATE INDEX [IX_FK_bn_ToaDieuTriCongCu_bn_HoSoBenhNhan]
ON [dbo].[bn_ToaDieuTriCongCu]
    ([IdBenhNhan]);
GO

-- Creating foreign key on [Id] in table 'bn_ToaThuoc'
ALTER TABLE [dbo].[bn_ToaThuoc]
ADD CONSTRAINT [FK_bn_ToaThuoc_bn_HoSoBenhNhan]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[bn_HoSoBenhNhan]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [IdToaThuoc] in table 'bn_ToaThuocChiTietBenhNhan'
ALTER TABLE [dbo].[bn_ToaThuocChiTietBenhNhan]
ADD CONSTRAINT [FK_bn_ToaThuocChiTietBenhNhan_bn_ToaThuoc]
    FOREIGN KEY ([IdToaThuoc])
    REFERENCES [dbo].[bn_ToaThuoc]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_bn_ToaThuocChiTietBenhNhan_bn_ToaThuoc'
CREATE INDEX [IX_FK_bn_ToaThuocChiTietBenhNhan_bn_ToaThuoc]
ON [dbo].[bn_ToaThuocChiTietBenhNhan]
    ([IdToaThuoc]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------